import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/components/health/text_ex.dart';
import 'package:flutter_eve_plugin/model/health/user_body_property.dart';
import 'package:flutter_eve_plugin/model/health/user_info.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class WeightPageHeadWidget extends StatelessWidget {
  const WeightPageHeadWidget({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(
        converter: (store) => AppStateViewModel(state: store.state),
        builder: (context, vm) {
          List<UserBodyDataInfo> infoList =
              vm.state.headlthState.userBodyModel.data;
          var weightList = infoList?.where((item) {
            return item.name == '体重';
          })?.toList();
          UserBodyDataInfo bodyInfo;
          if (weightList == null || weightList.isEmpty) {
            bodyInfo = UserBodyDataInfo('', '', '', 0, '', '', 0, 0, 0, 0, '',
                0, 0, 0, '', 0, '', '', '', '', '', null, '', null, '');
          } else {
            bodyInfo = weightList?.first;
          }
          UserInfoModel userInfo = vm.state.accountInfoState.userInfoModel;
          return Container(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Text(
                  '${userInfo.nickname}的琥珀 当前体重:',
                  style:
                      TextStyle(color: Colors.white, fontSize: setTextSp(13)),
                ),
                SizedBox(
                  height: setRatio(10),
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: <Widget>[
                    bodyInfo.value > 0
                        ? TextEx('${bodyInfo.value ~/ 1000}kg',
                            style: TextStyle(
                                color: Colors.white,
                                fontSize: setTextSp(24),
                                fontWeight: FontWeight.w500),
                            shadow: Color.fromRGBO(74, 70, 188, 1))
                        : Container(),
                    SizedBox(
                      width: setRatio(20),
                    ),
                    buildContainer(bodyInfo),
                    SizedBox(
                      width: setRatio(40),
                    ),
                  ],
                ),
              ],
            ),
            decoration: BoxDecoration(
              image: DecorationImage(
                  image: AssetImage(
                      imageUtilHuPo('health/icon_weight_bg@2x')),
                  fit: BoxFit.cover),
            ),
            width: setRatio(345),
            height: setRatio(95),
          );
        });
  }

  Container buildContainer(UserBodyDataInfo info) {
    ///1 骨瘦如柴； 2 身材偏瘦； 3 完美身材; 4 身体偏胖； 5 肥胖如猪
    switch (info.weightGrade) {
      case 1:
      case 5:
        return Container(
          child: FlatButton.icon(
              color: Colors.white,
              onPressed: () {},
              icon: Image.asset(
                imageUtilHuPo('health/icon_warning1@2x'),
                width: setRatio(12),
                height: setRatio(12),
              ),
              label: Text(
                info.weightType,
                style: TextStyle(
                    color: Color(0xFFF73E3E), fontSize: setTextSp(11)),
              ),
              shape: StadiumBorder()),
          height: setRatio(25),
        );
      case 2:
      case 4:
        return Container(
          child: FlatButton.icon(
              color: Colors.white,
              onPressed: () {},
              icon: Image.asset(
                imageUtilHuPo('health/icon_warning2@2x'),
                width: setRatio(12),
                height: setRatio(12),
              ),
              label: Text(
                info.weightType,
                style: TextStyle(
                    color: Color(0xFFF89D1A), fontSize: setTextSp(11)),
              ),
              shape: StadiumBorder()),
          height: setRatio(25),
        );
      case 3:
        return Container(
          child: FlatButton.icon(
              color: Colors.white,
              onPressed: () {},
              icon: Image.asset(
                imageUtilHuPo('health/icon_warning3@2x'),
                width: setRatio(12),
                height: setRatio(12),
              ),
              label: Text(
                info.weightType,
                style: TextStyle(
                    color: Color(0xFF7F79FF), fontSize: setTextSp(11)),
              ),
              shape: StadiumBorder()),
          height: setRatio(25),
        );
    }
    return Container();
  }
}
